package com.sl.au.repository;


import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.QuoteDevice;
import com.sl.au.entity.QuoteReplacement;

/**
 * 
 * @author XH
 *
 */
/**
 * @author asus1
 *
 */
@Transactional(readOnly = true)
public interface QuoteReplacementRepository extends JpaRepository<QuoteReplacement, String> {
	/**
	 * 得到外贸价格单生成对外价格单细目
	 * @param quoteForeignId 外贸价格单Id
	 * @return
	 */
	@Query(" select q from QuoteReplacement q where  q.quoteForeign.id=?1 order by createTime desc ")
	List<QuoteReplacement> findQuoteForeignOtherDeviceList(String quoteForeignId);
	
	@Query(" select q from QuoteReplacement q where  q.quote.id=?1 and q.indexOrder >?2 order by indexOrder asc ")
	List<QuoteReplacement> findNextQuoteReplacement(String nowQuoteId,int nowIndex);
	
	@Query(" select q from QuoteReplacement q where  q.quote.id=?1 and q.indexOrder <?2 order by indexOrder desc ")
	List<QuoteReplacement> findBeforeQuoteReplacement(String nowQuoteId,int nowIndex);
	
	/**分局quote的id找到记录
	 * @param quoteId
	 * @return
	 */
	@Query(" select q from QuoteReplacement q where  q.quote.id=?1 order by q.indexOrder asc ")
	List<QuoteReplacement>findByQuote_Id(String quoteId);


	QuoteReplacement findByContractIDAndIndexOrder(String contractID, int indexOrder);


	List<QuoteReplacement> findByContractID(String contractID);


	List<QuoteReplacement> findByContractIDAndIndexOrderGreaterThanEqualOrderByIndexOrderAsc(String contractID,
			int indexOrder);


	List<QuoteReplacement> findByContractIDAndIndexOrderGreaterThanEqualOrderByIndexOrderDesc(String contractID,
			int indexOrder);


	List<QuoteReplacement> findByContractIDOrderByIndexOrderDesc(String contractID);

	@Query(" select q from QuoteReplacement q where  q.quote.id=?1 and q.indexOrder =?2  ")
	QuoteReplacement findByQuoteIdAndIndexOrder(String quoteId, int nowIndex);
}
